require 'ostruct'

class Settings
  
  cattr_accessor :filepath, :config_, :contact_
  @@filepath = "#{RAILS_ROOT}/config/settings.yml"
  
  @@available_settings = YAML::load(File.open(@@filepath))
  
  def self.[](name)
    @@available_settings[name]
  end
  
  def self.config
     @@config_ ||= OpenStruct.new(@@available_settings['config'])
     @@config_
  end
  
  def self.contact
     @@contact_ = OpenStruct.new(@@available_settings['contact'])
     @@contact_
  end
  
  def self.contact=(values)
  	params = values.symbolize_keys
  	@@available_settings['contact']['subject'] = params[:subject]
  	@@available_settings['contact']['from'] = params[:from]
  end
  
  def self.save
  	File.open(@@filepath, 'w') { |f| f.puts YAML.dump(@@available_settings) }
  end
end
